# -*- coding: utf-8 -*-
from scpy.logger import get_logger
import os
import sys
import tornado.ioloop
import tornado.web
from handler import *

reload(sys)
sys.setdefaultencoding('utf-8')

logger = get_logger(__file__)

CURRENT_PATH = os.path.dirname(__file__)
if CURRENT_PATH:
    CURRENT_PATH = CURRENT_PATH + "/"

HandlerList = [
    (r"/index", IndexHandler),
    (r"/chart",ChartHandler),
    (r"/chart/companyInfo",CompanyChartHandler),
    # (r"/chart/industryInfo",RecruitmentChartHandler),
    (r"/chart/categoryInfo",CategoryChartHandler),
    (r"/index/recruitment/analysis", AnalysisHandler),
    (r"/query/companyList",MonitorCompanyListHandler),
    (r"/query/companyRecruitment", SearchCompanyRecruitmentInfoHandler),
    (r"/query/companyRecruitment/categoryType", SearchCategoryTypeInfoHandler),
    (r"/query/companyRecruitment/timeRange/detect", CompanyRecruitmentDetectorHandler),

    # time step
    (r"/query/companyRecruitment/timeStep",CompanyRecruitmentTimeStepHandler),
    # ready for java
    # 查询所有的简历与招聘 带分页
    (r"/query/companyRecruitment/timeRange", CompanyRecruimentSearchHandler),
    (r"/query/companyResume/timeRange", CompanyResumeSearchHandler),
    # 从有数据至今 发生数据变化的月份/每月平均工资/每月简历数量/每月简历类型分布
    (r"/query/groupInfo/timeStep", GroupMonthInfo),
    # 统计数据,用于报告
    (r"/query/companyResume/timeRange/statistic", CompanyResumeStatisticHandler),
    (r"/query/companyRecruitment/timeRange/statistic", CompanyRecruitmentStatisticHandler),
    # 用于头条,一段时间内每天的异常检查
    (r"/query/companyRecruitment/timeRange/compare", CompanyRecruitmentCompareHandler),
    (r"/query/companyResume/timeRange/compare", CompanyResumeCompareHandler),
]

templatePath = os.path.join(os.path.dirname(__file__), "template")
staticPath = os.path.join(os.path.dirname(__file__), "static")

if __name__ == '__main__':
    application = tornado.web.Application(HandlerList,template_path=templatePath,\
                                          static_path=staticPath)
    serverPort = 8000
    application.listen(serverPort)
    logger.info('server start at port %d'%serverPort
                )
    tornado.ioloop.IOLoop.instance().start()
